
/* ************************************************************************************* 
 * CREATED BY:          MYGENERATION
 * CREATED DATE:        12/25/2008
 * PROJECT:             MCWEBSITE
 * PURPOSE:             websiteProductTypeDAL class
 * MODIFIED BY:         None
 * MODIFIED DATE:       None
 * MODIFIED REASON:     None
 * NOTES:               None
 **************************************************************************************/
 
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Web.Configuration;
using MCWEBSITE.ENTITY;

namespace MCWEBSITE.DAL
{
    public class websiteProductTypeDAL
    {
        #region  Properties
		 
		public static string FIELD_PRODUCTTYPEID = "ProductTypeID";  
		public static string FIELD_LANGUAGECODE = "LanguageCode";  
		public static string FIELD_TYPECODE = "TypeCode";  
		public static string FIELD_TYPENAME = "TypeName";  
		public static string FIELD_DESCRIPTION = "Description";  
		public static string FIELD_ATRIBUTE1 = "Atribute1";  
		public static string FIELD_ATRIBUTE2 = "Atribute2";  
		public static string FIELD_ATRIBUTE3 = "Atribute3"; 
		public static string ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ContentConnectionString"].ToString();

        #endregion

        #region Protected methods

        /// <summary>
        /// Select entity of websiteProductType
        /// </summary>
        /// <param name="ProductTypeID">Primary Keys</param>
        /// <returns>Collection of websiteProductTypeInfo</returns>
        public static websiteProductTypeInfo SelectOne(int ProductTypeID)
        {
            websiteProductTypeInfo _websiteProductTypeInfo = new websiteProductTypeInfo();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteProductTypeSelectOne", ProductTypeID);
                if (dr.Read())
                    setwebsiteProductTypeInfo(dr, ref _websiteProductTypeInfo);
                return _websiteProductTypeInfo;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select all websiteProductType
        /// </summary>
        /// <returns>Collection of websiteProductTypeInfo</returns>
        public static List<websiteProductTypeInfo> SelectAll()
        {
            List<websiteProductTypeInfo> lstwebsiteProductType = new List<websiteProductTypeInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteProductTypeSelectAll");
                setListwebsiteProductTypeInfo(ref dr, ref lstwebsiteProductType);
                return lstwebsiteProductType;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select
        /// </summary>
        /// <param name="websiteProductTypenfo">Modify this method adapting your need</param>
        /// <returns>Collection of websiteProductTypeInfo</returns>
        public static List<websiteProductTypeInfo> SelectFilters(string strLanguage)
        {
            string criterias = string.Empty;
            List<websiteProductTypeInfo> lstwebsiteProductType = new List<websiteProductTypeInfo>();
            SqlDataReader dr = null;
            try 
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteProductTypeSelectByFilters", strLanguage);
                setListwebsiteProductTypeInfo(ref dr, ref lstwebsiteProductType);
                return lstwebsiteProductType;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Insert websiteProductType
        /// </summary>
        /// <param name="websiteProductTypeInfo">Entity of websiteProductType</param>
        /// <returns>error code</returns>
        public static int Insert(websiteProductTypeInfo _websiteProductTypeInfo)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteProductTypeInsert" 
											, _websiteProductTypeInfo.LanguageCode
											, _websiteProductTypeInfo.TypeCode
											, _websiteProductTypeInfo.TypeName
											, _websiteProductTypeInfo.Description											
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        
        /// <summary>
        /// Update websiteProductType
        /// </summary>
        /// <param name="websiteProductTypeInfo">Entity of websiteProductType</param>
        /// <returns>error code</returns>
        public static int Update(websiteProductTypeInfo _websiteProductTypeInfo)
        {            
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteProductTypeUpdate"
											, _websiteProductTypeInfo.ProductTypeID
											, _websiteProductTypeInfo.LanguageCode
											, _websiteProductTypeInfo.TypeCode
											, _websiteProductTypeInfo.TypeName
											, _websiteProductTypeInfo.Description											
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// Delete SchoolAdmin
        /// </summary>
        /// <param name="ProductTypeID">Primary Key</param>
        /// <returns>error code</returns>
        public static int Delete(int ProductTypeID)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteProductTypeDelete", ProductTypeID);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        #endregion

        #region "Utilities method"
		
        private static void setListwebsiteProductTypeInfo(ref SqlDataReader dr, ref List<websiteProductTypeInfo> lstwebsiteProductType)
        {
            websiteProductTypeInfo _websiteProductTypeInfo = null;
            while (dr.Read())
            {
                _websiteProductTypeInfo = new websiteProductTypeInfo();
                setwebsiteProductTypeInfo(dr, ref _websiteProductTypeInfo);
                lstwebsiteProductType.Add(_websiteProductTypeInfo);
            }
        }

        private static void setwebsiteProductTypeInfo(SqlDataReader dr, ref websiteProductTypeInfo _websiteProductTypeInfo)
        {
            _websiteProductTypeInfo.ProductTypeID = dr[websiteProductTypeDAL.FIELD_PRODUCTTYPEID] != DBNull.Value ? Convert.ToInt32(dr[websiteProductTypeDAL.FIELD_PRODUCTTYPEID]) : 0;
			_websiteProductTypeInfo.LanguageCode = dr[websiteProductTypeDAL.FIELD_LANGUAGECODE] != DBNull.Value ? Convert.ToString(dr[websiteProductTypeDAL.FIELD_LANGUAGECODE]) : string.Empty;
			_websiteProductTypeInfo.TypeCode = dr[websiteProductTypeDAL.FIELD_TYPECODE] != DBNull.Value ? Convert.ToString(dr[websiteProductTypeDAL.FIELD_TYPECODE]) : string.Empty;
			_websiteProductTypeInfo.TypeName = dr[websiteProductTypeDAL.FIELD_TYPENAME] != DBNull.Value ? Convert.ToString(dr[websiteProductTypeDAL.FIELD_TYPENAME]) : string.Empty;
			_websiteProductTypeInfo.Description = dr[websiteProductTypeDAL.FIELD_DESCRIPTION] != DBNull.Value ? Convert.ToString(dr[websiteProductTypeDAL.FIELD_DESCRIPTION]) : string.Empty;
			_websiteProductTypeInfo.Atribute1 = dr[websiteProductTypeDAL.FIELD_ATRIBUTE1] != DBNull.Value ? Convert.ToString(dr[websiteProductTypeDAL.FIELD_ATRIBUTE1]) : string.Empty;
			_websiteProductTypeInfo.Atribute2 = dr[websiteProductTypeDAL.FIELD_ATRIBUTE2] != DBNull.Value ? Convert.ToString(dr[websiteProductTypeDAL.FIELD_ATRIBUTE2]) : string.Empty;
			_websiteProductTypeInfo.Atribute3 = dr[websiteProductTypeDAL.FIELD_ATRIBUTE3] != DBNull.Value ? Convert.ToString(dr[websiteProductTypeDAL.FIELD_ATRIBUTE3]) : string.Empty;
			                        
        }
        #endregion Methods

        #region Private Members

        private static string TABLE_NAME = "[mc_websiteProductType]";

        #endregion
    }
}

		